
#ifndef __IEC101COMUSTATUS_H__
#define __IEC101COMUSTATUS_H__

#include "IEC101ProtocalDefineV1.h"
#define IEC101CMD_MAXLENGTH     256
#define IEC101_RETRY_TIMEOUT    10  //��
#define IEC101_MAX_RETRY_TIMES  3   //3��

extern uint16_t m_u16LinkAddress;

typedef enum 
{
	eStatus_ShakeHand = 0,
	eStatus_CallData,
	eStatus_DelayData, 
	eStatus_TimeData,
	eStatus_HeartBeat,
	eStatus_SponSOE,
	eStatus_SponMeasure,
	eStatus_WaitForData,
	
	eStatus_Fault_Report,        
	eStatus_TransRecData,       
	eStatus_CallRealTimeRecWave,
	eStatus_CallPastRecWave,      
  
    eStatus_SoftwareUpdate, 
	eStatus_Terminate_SoftwareUpdate, 
	eStatus_Complete_SoftwareUpdate
	  
} enumIEC101ComStatus;

typedef enum 
{
	eDetailNothing = 0,

	eShakeHand_Mas_ReqestLinkStatus,
	eShakeHand_Mas_ReqestLinkStatus_SlaResponse,
	eShakeHand_Mas_ResetLink,
	eShakeHand_Mas_ResetLink_SlaResponse,
	eShakeHand_Sla_ReqestLinkStatus,
	eShakeHand_Sla_ReqestLinkStatus_MasResponse,
	eShakeHand_Sla_ResetLink,
	eShakeHand_Sla_ResetLink_MasResponse,
	eShakeHand_Sla_ReportInitializeOver, 
	eShakeHand_Sla_ReportInitializeOver_MasResponse,
	//���ٻ�����
	eCallData_Mas_ReqestData,
	eCallData_Mas_ReqestData_SlaResponse,
	eCallData_Sla_ConfirmAct, 
	eCallData_Sla_ConfrimAct_MasResponse,
	eCallData_Sla_RemoteSignal,
	eCallData_Sla_RemoteSignal_MasResponse,
	eCallData_Sla_RemoteMeasure,
	eCallData_Sla_RemoteMeasure_MasResponse,
	eCallData_Sla_End,
	eCallData_Sla_End_MasResponse,
	//����
	eHeartBeat_Mas_Send,
	eHeartBeat_Mas_Send_SlaResponse,
	//��ʱ 
	eTimeCollect_Mas_SendTime,
	eTimeCollect_Mas_SendTime_SlaResponse,
	eTimeCollect_Sla_SendTime,
	eTimeCollect_Sla_SendTime_MasResponse,
	//ͻ��SOE
	eSponSignal_Sla_SendSponSOE,
	eSponSignal_Sla_SendSponSOE_MasResponse,
	//ͻ��ң��
	eSponMeasure_Sla_SendSponMeasure,
	eSponMeasure_Sla_SendSponMeasure_MasResponse,
	
	//-------------------------�쳣�����¼�����ݴ���------------------
	eReportFault_Sla_Reporting,       //��վ�����쳣
	eReportFault_Mas_Response,        //��վȷ��
	eReportFault_Mas_WaitingRecData,  //��վ�ȴ�¼������
	eReportFault_Mas_RecievingRecData,//��վ���ڽ����ն�¼������
	eReportFault_Sla_SendingRecData,
	eReportFault_Sla_SendingRecData_MasResponse,
	eReportFault_Sla_RecordWave,
	eReportFault_Sla_ReportFault_MasResponse,
	eReportFault_Sla_End,
	eReportFault_Sla_End_MasResponse,
	
	//------------------------- ��ʵʱ¼�����ݼ�����------------------
	eCallRealTimeRecWave_Mas_Request_file,
	eCallRealTimeRecWave_Mas_Request_file_Sla_Response,
	eCallRealTimeRecWave_Sla_Read_File_Activation_Confirm,
	eCallRealTimeRecWave_Sla_Read_File_Activation_Confirm_Mas_Response,
	eCallRealTimeRecWave_Sla_Trans_File,
	eCallRealTimeRecWave_Sla_Trans_File_Mas_Response,
	eCallRealTimeRecWave_Mas_Call_Data_STOP,
	eCallRealTimeRecWave_Mas_Call_Data_STOP_Confirm_Sla_Response,
	
	//-------------------------����ʷ¼�����ݼ�����------------------
	eCallPastRecWave_Mas_Request_file,
	eCallPastRecWave_Mas_Request_file_Sla_Response,
	eCallPastRecWave_Sla_Read_File_Activation_Confirm,
	eCallPastRecWave_Sla_Read_File_Activation_Confirm_Mas_Response,
	eCallPastRecWave_Sla_Trans_File,
	eCallPastRecWave_Sla_Trans_File_Mas_Response,
	eCallPastRecWave_Sla_Trans_Data_End,
	eCallPastRecWave_Sla_Trans_Data_End_Mas_Confirm,
	//------------------------��������-------------------------------
	eSoftwareUpdate_Mas_Request_SoftwareUpdate,
	eSoftwareUpdate_Mas_Request_TerminateSoftwareUpdate,
	eSoftwareUpdate_Mas_Request_Terminate_Sla_Response,
	eSoftwareUpdate_Mas_Request_Sla_Response,
	eSoftwareUpdate_Sla_ConfirmAct,
	eSoftwareUpdate_Sla_Terminate_ConfirmAct,
	eSoftwareUpdate_Sla_ConfirmAct_Mas_Response,
	eSoftwareUpdate_Sla_Terminate_ConfirmAct_Mas_Response,
	eSoftwareUpdate_Mas_Request_Complete_SoftwareUpdate,
	eSoftwareUpdate_Mas_Request_Complete_Sla_Response,
	eSoftwareUpdate_Sla_Complete_ConfirmAct,
	eSoftwareUpdate_Sla_Complete_ConfirmAct_Mas_Response,
	eSoftwareUpdate_Mas_WriteFile_Acton,
	eSoftwareUpdate_Mas_WriteFile_Acton_Sla_Response,
	eSoftwareUpdate_Mas_WriteFile_Acton_Sla_ConfirmAct,
	eSoftwareUpdate_Sla_WriteFile_ConfirmAct_Mas_Response,
	eSoftwareUpdate_Mas_Trans_Data,
	eSoftwareUpdate_Mas_Trans_Data_Sla_Response,
	eSoftwareUpdate_Mas_Trans_Data_Sla_Confirm,
	eSoftwareUpdate_Mas_Trans_Data_Sla_Confirm_mas_response	
} enumIEC101DetailStatus;

typedef enum 
{
	eWaitNothing = 0,
	eWaitConfirm,
	eWaitResponse
} enumIEC101WaitType;

typedef struct
{	
	unsigned char ucCMDLength; //�����
	unsigned char ucCMDBuf[IEC101CMD_MAXLENGTH];
	enumIEC101WaitType  eWait; 
	int nReTryTimes; //���Դ���
	TimeStruct waitStartTime;
}  SENDED_COMMAND;

typedef struct
{
	uint8_t *updateFileContent;
	uint32_t updateContentSize;
	uint32_t nextStoreIndex;
	uint32_t nextProgramFlashIndex;
	bool   imageReady;
} UPDATEFILECONTENT_T;



//--------------------��������-------------------

typedef enum RESULT
{
	enum_Succeed = 0,
	enum_UnkownFault,
	enum_FileNameNotSupported,
	enum_LenOutrange
	
} RESULTDES_T;

//��������ӳ�����ݴ������
typedef enum IMAGERESULT
{
	enum_Image_Succeed = 0,
	enum_Image_UnkownFault,
	enum_Image_CheckCodeError,
	enum_Image_FileLenFault,
	enum_Image_FileIDError
} IMAGESTATUS_T;

#define NEED_PARSE_NOTHING           -1
#define NEED_PARSE_SIGNAL             0
#define NEED_PARSE_MEASURE            1
#define NEED_PARSE_SIGNAL_EMERGENCY   2
#define NEED_PARSE_MEASURE_EMERGENCY  3
#define NEED_PARSE_TIME               4
//-------------------------�쳣�����¼�����ݴ���------------------
#define NEED_PARSE_FAULT_REPORT_REC_WAVE    5 //���ϱ���¼������֡����
#define NEED_PARSE_REALTIME_REC_WAVE        6 //ʵʱ¼������֡����
#define NEED_PARSE_REALTIME_SLA_ACTIVATE    7
#define NEED_PARSE_PAST_REC_WAVE            8 //ʵʱ¼������֡����
#define NEED_PARSE_FAULT_REPORT_START_TIME  9 //�����ն˹��ϱ���֡


extern SENDED_COMMAND m_SendedCMD;
extern uint16_t m_u16LinkAddress;
extern UPDATEFILECONTENT_T m_pSoftwareUpdate;

extern void ParseStatusFromFrameFix(FIXEDFRAME* pFrameFix);
extern void MakeDefaultCommand(uint16_t __u16LinkAddress);
extern int  ParseStatusFromFrameVar(FRAME_VAR_HEAD* pFrameVar);
extern uint8_t CheckTimeOutStatus(void);
//-----------------------------�쳣�����¼�����ݴ���-----------------------------
extern  bool    SendFaultReportFrame(CP56Time2a *);       //����¼����ʼͨ�棬һ��¼����ʼ


#endif

